#include<iostream.h>
void menu();
int count=0;
void avg(float);
class stack
			  {
			  private:
						 int element;
                                                 float m1;
                                                 float m2;
						 stack *next;
			  public:
						stack* enqueue(int,float,float);
						stack* dequeue(int);
						void stack_display(stack*);
                                                void stack_display1(stack*);
                                                void stack_display2(stack*);
                                                void stack::stack_avg(stack*);
			  }*head,*trial;
stack* stack::enqueue(int id,float a,float b)
{
 stack *temp,*temp1;
 temp1=head;
 temp=new stack;
 trial=temp;
 temp->element=id;
 temp->m1=a;
 temp->m2=b;
 temp->next=NULL;
 if(head==NULL)
		head=temp;
 else
	  {
		 while(temp1->next!=NULL)
		    temp1=temp1->next;
		 temp1->next=temp;
	  }
 return head;
 }
 stack* stack::dequeue(int x)
 {
	stack *temp,*temp1,*d;
	temp=head;
	temp1=head;
   if(temp->element==x)
    {
    head=head->next;
    count--;
    }
    else
     {
	     while(temp->next->element!=x)
		  {
		  temp=temp->next;
		  }
		   d=temp->next;
         count--;
         temp->next=d->next;
     }
	return head;


 }

 void stack::stack_display(stack* head)
 {
 stack* temp;
 float mark;
 temp=head;
 if(temp!=NULL)
	{ cout<<"id\tmark1\tmark2\tsum\tavreag\n";
	 while(temp->next!=NULL)
			{
         mark=temp->m1+temp->m2;
			cout<<temp->element<<"\t"<<temp->m1<<"\t"<<temp->m2<<"\t";
         avg(mark);
			temp=temp->next;
			}
         mark=temp->m1+temp->m2;
         cout<<temp->element<<"\t"<<temp->m1<<"\t"<<temp->m2<<"\t";
         avg(mark);
			cout<<endl;
	 }
 else
	  cout<<"The Stack Is Empty\n";
 }
void stack::stack_display1(stack* head)
 {
 float mark;
 stack* temp;
 temp=head;
 if(temp!=NULL)
	{ cout<<"id\tmark1\tmark2\tsum\tavreag\n";
	 while(temp->next!=NULL)
			{
         mark=temp->m1+temp->m2;
         if(mark>=60)
			cout<<temp->element<<"\t"<<temp->m1<<"\t"<<temp->m2<<"\t";
         if(mark>=60)
         avg(mark);
			temp=temp->next;
			}
         mark=temp->m1+temp->m2;
         if(mark>=60)
         cout<<temp->element<<"\t"<<temp->m1<<"\t"<<temp->m2<<"\t";
         if(mark>=60)
         avg(mark);
			cout<<endl;
	 }
 else
	  cout<<"The Stack Is Empty\n";
 }
void stack::stack_display2(stack* head)
 {
 float mark;
 stack* temp;
 temp=head;
 if(temp!=NULL)
	{ cout<<"id\tmark1\tmark2\tsum\tavreag\n";
	 while(temp->next!=NULL)
			{
         mark=temp->m1+temp->m2;
         if(mark<60)
			cout<<temp->element<<"\t"<<temp->m1<<"\t"<<temp->m2<<"\t";
         if(mark<60)
         avg(mark);
			temp=temp->next;
			}
         mark=temp->m1+temp->m2;
         if(mark<60)
         cout<<temp->element<<"\t"<<temp->m1<<"\t"<<temp->m2<<"\t";
         if(mark<60)
         avg(mark);
			cout<<endl;
	 }
 else
	  cout<<"The Stack Is Empty\n";
 }
  void stack::stack_avg(stack* head)
 {
 int sum=0,avg,mark=0;
 stack* temp;
 temp=head;
 if(temp!=NULL)
	{
	 while(temp->next!=NULL)
			{
          mark=temp->m1+temp->m2;
          sum=sum+mark;
			temp=temp->next;
			}
			mark=temp->m1+temp->m2;
          sum=sum+mark;
	 avg=sum/count;
	 cout<<avg;
	 }
 else
	  cout<<"The Stack Is Empty\n";
 }


									  int main()
{
int c,x,z,y;
float a,b;
stack object;
head=trial=NULL;
menu();
cin>>c;
while(c!=8)
		{
		switch(c)
				  {
				  case 1:
							cout<<"\n Enter id student :  ";
							cin>>x;
                     cout<<"\n Enter mark1 student :  ";
                     cin>>a;
                      cout<<"\n Enter mark2 student :  ";
                     cin>>b;
                     count++;
							head=object.enqueue(x,a,b);
							break;
				  case 2:
                     cout<<"enter id\t";
                     cin>>y;
							head=object.dequeue(y);
							break;
				  case 3:
							cout<<"\n-------------------------------------------\n";
							object.stack_display(head);
							cout<<"-------------------------------------------\n";
							break;
              case 4:
							cout<<"\n-------------------------------------------\n";
							object.stack_display1(head);
							cout<<"-------------------------------------------\n";
							break;
              case 5:
							cout<<"\n-------------------------------------------\n";
							object.stack_display2(head);
							cout<<"-------------------------------------------\n";
							break;
              case 6:
							cout<<"\n-------------------------------------------\n";
							object.stack_avg(head);
							cout<<"\n-------------------------------------------\n";
							break;
              case 7:
                     cout<<"\n-------------------------------------------\n";
							cout<<"count student =  "<<count;
							cout<<"\n-------------------------------------------\n";
                     break;
				  default:
							cout<<"Pl Enter Your Choice.(1,2,3,4)--->";
				  }
		menu();
		cin>>c;
}
return 0;
}

 void menu()
 {
  cout<<"\n       main menu  \n";
  cout<<"____________________________";
  cout<<"\n1>Add data student\n";
  cout<<"2>Delete student\n";
  cout<<"3>Display data all studentn\n";
  cout<<"4>Display data pass studentn\n";
  cout<<"5>Display data rasep studentn\n";
  cout<<"6>Display avreag student\n";
  cout<<"7>Display count student\n";
  cout<<"8>Exit\n";
 }
 void avg(float mark)
   {
         if(mark>=90)
            	cout<<mark<<"\t"<<"A"<<"\n";
         else if(mark>=80&&mark<90)
         	cout<<mark<<"\t"<<"B"<<"\n";
         else if(mark>=70&&mark<80)
             	cout<<mark<<"\t"<<"C"<<"\n";
         else if(mark>=60&&mark<70)
         	cout<<mark<<"\t"<<"D"<<"\n";
         else if(mark>=0&&mark<60)
			cout<<mark<<"\t"<<"E"<<"\n";
   }